/*
	Copyright (c) 2010 <copyright holders>
	This source code is licensed under The MIT License,
	see the file LICENSE for details.
	*/

#ifndef GAME_HPP
#define GAME_HPP

#include <OGRE/OgrePrerequisites.h>
#include <string>

#include "ForwardDecls.hpp"
#include "HelpDefs.hpp"

namespace spelprog2 {

//class is a ****ing mess and disagrees with just about any code design principle.
	//needs to be rewritten where possible
class Game {
    HIDE_EVIL_CONSTRUCTORS(Game);

	lua::Engine * lengine;

    //these are normal pointers because boost manages them anyway (except root)
    Ogre::Root * root_;
    Ogre::RenderWindow * window_;
    Ogre::Viewport * view_;
    Ogre::RenderTarget * renderTarget_;
    Ogre::Camera * camera_;
    Ogre::Camera * topDownCamera_;

	//test
	irrklang::ISoundEngine * soundEngine_;

    net::Net * net_;
    presentation::Presentation * presentation_;
    presentation::Presentation * queuedPresentation_;
    FrameHandler * frameHandler_;
	sim::WorldManager * worldMan_;

    //parameters to store net config
    enum NetMode {
        LOCAL,
        SERVER,
        CLIENT
    };
    NetMode netInitMode_;
    std::string host_;
    unsigned port_;
    std::string username_;
    std::string password_;

    void initCamera();
public:
    Game(const Ogre::String & ogrePluginFile);
    ~Game();
    void run();
    void locateResources(const Ogre::String & filename);
    void setAsClient(const std::string & username, const std::string & password,
        const std::string & host, unsigned port);
    void setAsServer(const std::string & username, const std::string & password,
        unsigned port);
    void setAsLocal();
    void initNet();
    void quit();
    void queuePresentation(presentation::Presentation * newPresentation);
    void present();
    Ogre::RenderTarget *setupRTTTarget(const Ogre::String & name, int width = 512, int height = 512);
    void initTopDownCamera();
    void updateTopDownCamera();

    //accessors
    Ogre::Root & getRoot()                          { assert(root_); return *root_; }
    Ogre::RenderWindow & getWindow()                { assert(window_); return *window_; }
    Ogre::Viewport & getViewport()                  { assert(view_); return *view_; }
    Ogre::Camera & getCamera()                      { assert(camera_); return *camera_; }
    net::Net & getNetworking()                      { assert(net_); return *net_; }
    sim::WorldManager & getWorldManager()           { assert(worldMan_); return *worldMan_; }
    presentation::Presentation & getPresentation()  { assert(presentation_); return *presentation_; }
};

};

#endif //GAME_HPP
